<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>学生管理系统</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            padding: 8px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .pagination {
            margin-top: 20px;
        }
        .pagination a {
            padding: 8px 16px;
            text-decoration: none;
            border: 1px solid #ddd;
        }
        .pagination a.active {
            background-color: #4CAF50;
            color: white;
            border: 1px solid #4CAF50;
        }
        .pagination a:hover:not(.active) {
            background-color: #ddd;
        }
    </style>
</head>
<body>
    <h1>学生管理系统</h1>
    <a href="${pageContext.request.contextPath}/student/add">新增学生</a>
    <table>
        <tr>
            <th>ID</th>
            <th>姓名</th>
            <th>出生日期</th>
            <th>备注</th>
            <th>平均分</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${students}" var="student">
            <tr>
                <td>${student.id}</td>
                <td>${student.name}</td>
                <td><fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd"/></td>
                <td>${student.description}</td>
                <td>${student.avgscore}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/student/edit/${student.id}">修改</a>
                    <a href="${pageContext.request.contextPath}/student/delete/${student.id}" onclick="return confirm('确定要删除吗?')">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    
    <div class="pagination">
        <c:if test="${currentPage > 1}">
            <a href="${pageContext.request.contextPath}/student/list?page=${currentPage - 1}">上一页</a>
        </c:if>
        
        <c:forEach begin="1" end="${totalPages}" var="pageNum">
            <c:choose>
                <c:when test="${pageNum == currentPage}">
                    <a href="#" class="active">${pageNum}</a>
                </c:when>
                <c:otherwise>
                    <a href="${pageContext.request.contextPath}/student/list?page=${pageNum}">${pageNum}</a>
                </c:otherwise>
            </c:choose>
        </c:forEach>
        
        <c:if test="${currentPage < totalPages}">
            <a href="${pageContext.request.contextPath}/student/list?page=${currentPage + 1}">下一页</a>
        </c:if>
    </div>
</body>
</html>    